/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Solitare;

/**
 *
 * @author User
 */
class SuitPile extends CardPile {

	SuitPile(int x, int y) {
		super(x, y);
	}

	public boolean canTake(Card aCard) {
		if (isEmpty())
			return aCard.rank() == 0;
		Card topCard = top();
		return (aCard.suit() == topCard.suit())
				&& (aCard.rank() == 1 + topCard.rank());
	}
	public void select(int tx, int ty) {
		if(Solitare.selected && !Solitare.allPiles[Solitare.key].isEmpty() && Solitare.allPiles[Solitare.key].top().faceUp())
		{
		Card topCard=Solitare.allPiles[Solitare.key].top();
		if (Solitare.allPiles[Solitare.key].peaks>1) return;
		if (Solitare.allPiles[Solitare.cur].canTake(topCard)) {
			Solitare.allPiles[Solitare.cur].addCard(topCard);
			Solitare.allPiles[Solitare.key].pop();
			return;
		}
		}
	}

}